package com.example.demo

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import com.example.demo.utils.LocalManageUtil

class SettingActivity : BaseActivity() {
    companion object{
        fun enter(context: Context){
            val intent = Intent(context, SettingActivity::class.java)
            context.startActivity(intent)
        }
    }

    lateinit var mUserSelect:TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_setting)
        mUserSelect = findViewById(R.id.tv_user_select)
        mUserSelect.text = getString(R.string.user_select_language,
            LocalManageUtil.getSelectLanguage(this))
        setClick()
    }

    private fun setClick() {
        // 跟随系统
        findViewById<Button>(R.id.btn_auto).setOnClickListener {
            selectLanguage(0)
        }
        // 简体中文
        findViewById<Button>(R.id.btn_cn).setOnClickListener {
            selectLanguage(1)
        }
        // 繁体中文
        findViewById<Button>(R.id.btn_traditional).setOnClickListener {
            selectLanguage(2)
        }
        // 英语
        findViewById<Button>(R.id.btn_en).setOnClickListener {
            selectLanguage(3)
        }


    }

    private fun selectLanguage(select: Int) {
        LocalManageUtil.saveSelectLanguage(this, select)
        MainActivity.restart(this)
    }

}